#!/usr/bin/env python3
# filename: manage.py

import os

from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from hzsaiblog import models
from hzsaiblog import create_app

# get the env from os_env
env = os.environ.get('BLOG_ENV', 'dev')

app = create_app('hzsaiblog.config.%sconfig' % env.capitalize())

# init the manager via main.app
manager = Manager(app)

# init migrate obj via main.app and db
migrate = Migrate(app, models.db)

# create new command
server = Server(host="127.0.0.1", port=5000)
manager.add_command("runserver", server)
manager.add_command("db", MigrateCommand)


@manager.shell
def make_shell_context():
    """Create a python CLI.

    return : Default import object
    type:`Dict`
    """
    return dict(app=app,
                db=models.db,
                User=models.User,
                Post=models.Post,
                Comment=models.Comment,
                Tag=models.Tag,
                Role=models.Role)


if __name__ == '__main__':
    manager.run()
